home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 June / macformat-038.iso / Shareware in MacFormat / Creator Changer 2.5 / Code & Resource / Creator Changer.start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-09  |  4.8 KB  |  211 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the functions which start off the program.  The
  3.  *    main event loop and Macintosh toolbox definitions are in this
  4.  *    file.
  5.  **********************************************************************/
  6.  
  7. #include "Creator Changer.h"
  8. #include "Creator Changer.start.h"
  9.  
  10.  
  11. /**********************************************************************
  12.  *    Function main(), this is the main function of the program.  The 
  13.  *    major parts of the program are called in this function.
  14.  **********************************************************************/
  15.  
  16. void main(void)
  17.     {
  18.     
  19.     Init_Toolbox();
  20.     Get_Strings();
  21.     Check_Sys_Type();
  22.     Install_AE_Handlers();
  23.     Set_Up_Menu_Bar();
  24.     Open_Preferences();
  25.     
  26.     while(!All_Done) Handle_One_Event();
  27.  
  28.     }
  29.     
  30.  
  31. /**********************************************************************
  32.  *    Function Handle_One_Event(), this function handles one event.  
  33.  *    Depending on what the event is, it gets directed to the 
  34.  *    appropriate place.
  35.  **********************************************************************/
  36.  
  37. void Handle_One_Event(void) 
  38.     {
  39.     
  40.     Boolean  event_was_dialog;
  41.     
  42.     WaitNextEvent(everyEvent, &The_Event, SLEEP_TICKS, MOUSE_REGION);
  43.         
  44.     switch(The_Event.what)
  45.         {
  46.         case mouseDown: 
  47.             Handle_Mouse_Down();
  48.             break;
  49.         case keyDown:
  50.         case autoKey:
  51.             {
  52.             register char command_key=The_Event.message;    
  53.             
  54.             if(The_Event.modifiers!=0) Handle_Menu_Choice(MenuKey(command_key));
  55.             }
  56.             break;
  57.         case kHighLevelEvent:
  58.             Control_Key_Down=Is_Pressed(58);
  59.             AEProcessAppleEvent(&The_Event);
  60.             break;
  61.         }
  62.     
  63.     }
  64.  
  65.  
  66.  
  67. /**********************************************************************
  68.  *    Function Handle_Mouse_Down(), this function handles any mouse down
  69.  *    event, such as a window select, in the menu bar etc.
  70.  **********************************************************************/
  71.  
  72. void Handle_Mouse_Down(void)
  73.     {
  74.     
  75.     WindowPtr    which_window;
  76.     short        the_part;
  77.     long        menu_choice;
  78.     Rect        drag_rect;
  79.  
  80.     the_part=FindWindow(The_Event.where, &which_window);  
  81.     
  82.     switch(the_part)
  83.         {
  84.         case inMenuBar:
  85.             menu_choice=MenuSelect(The_Event.where);
  86.             Handle_Menu_Choice(menu_choice);              
  87.             break;
  88.         case inSysWindow: 
  89.             SystemClick(&The_Event, which_window);
  90.             break;
  91.         case inContent:
  92.             SelectWindow(which_window);
  93.             break;
  94.         default:
  95.             break;
  96.         }
  97.  
  98.     }
  99.  
  100.  
  101.  
  102. /**********************************************************************
  103.  *    Function Handle_Menu_Choice(), this function handles the menu 
  104.  *    choice made, then it directs it to the appropriate place.
  105.  **********************************************************************/
  106.  
  107. void Handle_Menu_Choice(long menu_choice)
  108.     {
  109.     
  110.     if(menu_choice!=0)
  111.         {
  112.         switch(HiWord(menu_choice))
  113.             {
  114.             case APPLE_MENU_ID:
  115.                 Handle_Apple_Choice(LoWord(menu_choice));
  116.                 break;
  117.             case OPTIONS_MENU_ID:
  118.                 Handle_Options_Choice(LoWord(menu_choice));
  119.                 break;
  120.             defualt:
  121.                 break;
  122.             }
  123.         HiliteMenu(0);
  124.         }
  125.     
  126.     }
  127.  
  128.  
  129.  
  130. /**********************************************************************
  131.  *    Function Handle_Apple_Choice(), this function decides what item 
  132.  *    to execute under the apple menu.
  133.  **********************************************************************/
  134.  
  135. void Handle_Apple_Choice(int the_item)
  136.     {
  137.     
  138.     Str32    desk_acc_name;
  139.     int        desk_acc_number;
  140.     short    the_dialog_item;
  141.     
  142.     switch(the_item)
  143.         {
  144.         case A_ABOUT_ITEM:
  145.             {
  146.             DialogPtr    about_dialog;
  147.             Boolean    done=FALSE;
  148.             GrafPtr        old_port;
  149.             
  150.             GetPort(&old_port);
  151.             about_dialog=GetNewDialog(ABOUT_DLOG_ID, About_Storage, IN_FRONT);
  152.             ShowWindow(about_dialog);
  153.             while(!done)
  154.                 {
  155.                 Draw_Border(about_dialog, ABOUT_OK, YES);
  156.                 ModalDialog(NIL_PTR, &the_dialog_item);
  157.                 switch(the_dialog_item)
  158.                     {
  159.                     case ABOUT_OK:
  160.                         done=TRUE;
  161.                         break;
  162.                     default:
  163.                         break;
  164.                     }
  165.                 }
  166.             CloseDialog(about_dialog);
  167.             SetPort(old_port);
  168.             }
  169.             break;
  170.         default:
  171.             GetItem(Apple_Menu, the_item, desk_acc_name);
  172.             desk_acc_number=OpenDeskAcc(desk_acc_name);
  173.             break;
  174.         }
  175.     
  176.     }
  177.  
  178.  
  179.  
  180. /**********************************************************************
  181.  *    Function Handle_Options_Choice(), this function decides what item
  182.  *    to execute under the options menu.
  183.  **********************************************************************/
  184.  
  185. void Handle_Options_Choice(int the_item)
  186.     {
  187.     
  188.     switch(the_item)
  189.         {
  190.         case O_OPEN_ITEM:
  191.             if(Pick_File(&The_File_Spec, &File_Info, TRUE))
  192.                 {
  193.                 Multiple_Files=NO;
  194.                 Open_DLOG(&Chng_Dialog, PREF_TYPES_ID, PREF_PT, CHNG_TYPE_DLOG_ID, Num_pt, Chng_Storage, NIL_PTR, one_file);
  195.                 }
  196.             break;
  197.         case O_EDIT_LIST:
  198.             Open_DLOG(&Edit_Dialog, PREF_TYPES_ID, PREF_PT, EDIT_LIST_DLOG_ID, Num_pt, Edit_Storage, NIL_PTR, NIL_PTR);
  199.             break;
  200.         case O_AUTO_ITEM:
  201.             Open_DLOG(&Auto_Dialog, AUTO_CHANGE_ID, PREF_AC, AUTO_CHANGE_DLOG_ID, Num_ac, Auto_Storage, NIL_PTR, NIL_PTR);
  202.             break;
  203.         case O_QUIT_ITEM:
  204.             All_Done=TRUE;
  205.             break;
  206.         default:
  207.             break;
  208.         }
  209.     
  210.     }
  211.